package top.codedance.iotp.server.net.handle;

import cd.io.netty.channel.ChannelHandlerContext;
import cd.io.netty.channel.SimpleChannelInboundHandler;
import cd.io.netty.handler.codec.http.FullHttpRequest;
import top.codedance.iotp.server.ServerApplication;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class WsChannelAuthHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
    private static Logger logger = ServerApplication.getLogger(WsChannelAuthHandler.class);
    public static volatile Map<String, FullHttpRequest> wsReqests = new HashMap<>();

    @Override
    protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
        String clientId = WsChannelHandler.getClientId(ctx);
        synchronized (WsChannelAuthHandler.class) {
            wsReqests.put(clientId, request);
        }
        ctx.fireChannelRead(request.retain());
        ctx.pipeline().remove(WsChannelAuthHandler.class);
    }
}
